package com.example.housekeeping.controller;


import com.example.housekeeping.pojo.dto.ServeItemAddNewDTO;
import com.example.housekeeping.pojo.dto.ServeItemUpdateDTO;
import com.example.housekeeping.pojo.entity.ServeItem;
import com.example.housekeeping.pojo.vo.ServeItemListItemVO;
import com.example.housekeeping.pojo.vo.ServeItemStandardVO;
import com.example.housekeeping.pojo.vo.ServeKindsListItemVO;
import com.example.housekeeping.pojo.vo.WorkerListItemVO;
import com.example.housekeeping.service.ServeItemService;
import com.example.housekeeping.service.ServeKindsService;
import com.example.housekeeping.service.WorkerService;
import com.example.housekeeping.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务项目管理（新增、删除、更改等业务）
 *
 * @author 王洪
 */
@RestController
@Slf4j
@MapperScan("com.example.housekeeping.mapper")
@Api(tags = "服务项目管理模块")
@Validated
@RequestMapping("/serve-item")
public class ServeItemController {

    @Autowired
    private ServeItemService service;

    @Autowired
    private ServeKindsService kindsService;

    @Autowired
    private WorkerService workerService;

    @ApiOperation("新建服务项目")
    @PostMapping("/add-new")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> serveAddNew(ServeItemAddNewDTO serveItemAddNewDTO) {
        log.debug("开始处理【新增服务项目】业务，参数:{}", serveItemAddNewDTO);
        service.addNew(serveItemAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除模块")
    @GetMapping("/delete/{id}")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> deleteById(@PathVariable(value = "id") Long id) {
        log.debug("开始处理【根据id删除数据】的业务，id:{}", id);
        service.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改数据模块")
    @PostMapping("/update/{id}")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> updateById(@PathVariable Long id,ServeItemUpdateDTO serveItemUpdateDTO) {
        log.debug("开始处理【根据id修改数据】的业务，id:{},参数:{}", id, serveItemUpdateDTO);
        service.updateById(id,serveItemUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("通过id查询数据模块")
    @GetMapping("/select/{id}")
    @ApiOperationSupport(order = 400)
    public JsonResult<ServeItemStandardVO> getStandById(@PathVariable(value = "id") Long id) {
        ServeItemStandardVO standardById = service.getStandardById(id);
        return JsonResult.ok(standardById);
    }

    @ApiOperation("查询数据列表")
    @GetMapping("/list")
    @ApiOperationSupport(order = 500)
    public JsonResult<List<ServeItemListItemVO>> list() {
        log.debug("开始查询列表");
        List<ServeItemListItemVO> list = service.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据服务员Id查询数据")
    @GetMapping("/selectByWorkerId")
    @ApiOperationSupport(order = 500)
    public JsonResult<ServeItem> selectByWorkerId(Long workerId) {
        log.debug("开始根据服务员Id查询数据");
        ServeItem serveItem = service.selectByWorkerId(workerId);
        return JsonResult.ok(serveItem);
    }
}
